//
//  RecordListController.m
//  FinancialProduct
//  交易记录
//  Created by Stella on 2017/9/4.
//  Copyright © 2017年 maq. All rights reserved.
//
#import "MJRefresh.h"
#import "HandleNetProduct.h"
#import "ProductListCell.h"
#import "RecordListController.h"
#import "RecordModel.h"
#import "UserModel.h"
@interface RecordListController (){
    int count;
}
@property (weak, nonatomic) IBOutlet UIView *noDataView;
@property(nonatomic,strong)NSMutableArray *DataArray;
@property (weak, nonatomic) IBOutlet UITableView *mTableView;
@end

@implementation RecordListController

- (void)viewDidLoad {
    [super viewDidLoad];
    _DataArray=[[NSMutableArray alloc] init];
    count=1;
    _mTableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        count=1;
        [self getDetailInfo];
    }];
    _mTableView.mj_footer =[MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
        count++;
       [self getDetailInfo];
    }];
    
    // 马上进入刷新状态
    [self.mTableView.mj_header beginRefreshing];
    
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)getDetailInfo{
    /*
     * Contractno 产品合同号
     * CurrencyType 币种
     * Templet 模板
     */
    UserModel *model=[UserModel getUser];
    int mid=[model.CustomerID intValue];
    NSDictionary *params=@{@"AAAMethodName":@"Transactiondetail",@"CustomerID":@(mid),
                           
                           @"Contractno":self.infoDic[@"Contractno"],
                           @"CurrencyType":self.infoDic[@"CurrencyType"],
                           @"PageIndex":@(count),@"PageSize":@(20)};
    NSLog(@"params===%@",params);
    [HandleNetProduct getInvestAssetListforParams:params Success:^(NSArray *data) {
        [self.mTableView.mj_header endRefreshing];
        [self.mTableView.mj_footer endRefreshing];
        if (count==1) {
            [self.DataArray removeAllObjects];
        }
        if (data.count>0) {
         
            [self.DataArray addObjectsFromArray:data];
          
        }
        if (self.DataArray.count>0) {
            self.noDataView.hidden=YES;
        }else{
            self.noDataView.hidden=NO;
        }
        [self.mTableView reloadData];
    } Failure:^(NSString *errorInfo) {
        [self.mTableView.mj_header endRefreshing];
        [self.mTableView.mj_footer endRefreshing];
    }];
}
#pragma mark - Table view data source
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 123;
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    
    return self.DataArray.count;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return 1;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    ProductListCell *cell=[tableView dequeueReusableCellWithIdentifier:@"ProductListCell" forIndexPath:indexPath];
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    cell.accessoryType=UITableViewCellAccessoryNone;
    NSDictionary *dic=self.DataArray[indexPath.section];
    RecordModel *model=[RecordModel mj_objectWithKeyValues:dic];
    cell.recordModel=model;
    [cell layoutIfNeeded];
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 0.01f;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 10;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

}

@end
